

'----------------------------------------------------------------------------
' Hands-On 21-1
'----------------------------------------------------------------------------

Sub ShortcutMenus()
    Dim myBar As CommandBar
    Dim counter As Integer

    For Each myBar In CommandBars
        If myBar.Type = msoBarTypePopup Then
            counter = counter + 1
            Debug.Print counter & ": " & myBar.Name
        End If
    Next
End Sub


'----------------------------------------------------------------------------
' Hands-On 21-2
'----------------------------------------------------------------------------

Sub AddToCellMenu()
    With Application.CommandBars("Cell")
        .Reset
        .Controls.Add(Type:=msoControlButton, _
            Before:=2).Caption = "Insert Picture..."
        .Controls("Insert Picture...").OnAction = "InsertPicture"
    End With
End Sub


Sub AddToCellMenu2()
    Dim ct As CommandBarButton
    
    With Application.CommandBars("Cell")
        .Reset
        Set ct = .Controls.Add(Type:=msoControlButton, _
            Before:=11, Temporary:=True)
    End With
    With ct
        .Caption = "Insert Pict&ure..."
        .OnAction = "InsertPicture"
        .Picture = Application.CommandBars. _
            GetImageMso("PictureInsertFromFile", 16, 16)
        .Style = msoButtonIconAndCaption
    End With
End Sub


Sub DeleteInsertPicture()
    Dim c As CommandBarControl
    On Error Resume Next
    Set c = CommandBars("Cell").Controls("Insert Pict&ure...")
    c.Delete
End Sub


'-----------------------------------------------------------------------------
' Code to be entered in the ThisWorkbook Code Module
'-----------------------------------------------------------------------------

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call DeleteInsertPicture
End Sub


Private Sub Workbook_Open()
    Call AddToCellMenu
End Sub


'------------------------------------------------------------------------------
' Code to be entered in the Sheet1 Code Module
'------------------------------------------------------------------------------

Private Sub Worksheet_Activate()
    Application.CommandBars("Cell").Controls("Sort").Enabled = False
End Sub


Private Sub Worksheet_Deactivate()
    Application.CommandBars("Cell").Controls("Sort").Enabled = True
End Sub



'------------------------------------------------------------------------------
' Hands-On 21-3
'------------------------------------------------------------------------------

Sub Create_ShortcutMenu()
    Dim sm As Object

    Set sm = Application.CommandBars.Add("MyComputer", msoBarPopup)
    With sm
        .Controls.Add(Type:=msoControlButton).Caption = "Operating System"
        With .Controls("Operating System")
            .FaceId = 1954
            .OnAction = "OpSystem"
        End With
        .Controls.Add(Type:=msoControlButton).Caption = "Active Printer"
        With .Controls("Active Printer")
            .FaceId = 4
            .OnAction = "ActivePrinter"
        End With
        .Controls.Add(Type:=msoControlButton).Caption = "Active Workbook"
        With .Controls("Active Workbook")
            .FaceId = 247
            .OnAction = "ActiveWorkbook"
        End With
        .Controls.Add(Type:=msoControlButton).Caption = "Active Sheet"
        With .Controls("Active Sheet")
            .FaceId = 18
            .OnAction = "ActiveSheet"
        End With
    End With
End Sub


Sub OpSystem()
    MsgBox Application.OperatingSystem, , "Operating System"
End Sub


Sub ActivePrinter()
    MsgBox Application.ActivePrinter
End Sub


Sub ActiveWorkbook()
    MsgBox Application.ActiveWorkbook.Name
End Sub


Sub ActiveSheet()
    MsgBox Application.ActiveSheet.Name
End Sub



'----------------------------------------------------------------------------
' Code to be entered in the UserForm1 Code Module
'----------------------------------------------------------------------------

Private Sub CommandButton1_MouseDown(ByVal Button _
        As Integer, _
        ByVal Shift As Integer, _
        ByVal X As Single, _
        ByVal Y As Single)
    If Button = 2 Then
        Call Show_ShortMenu
    Else
        MsgBox "You must right-click this button."
    End If
End Sub



'----------------------------------------------------------------------------
' Code to be entered in the ShortcutMenus Code window
'----------------------------------------------------------------------------

Sub Show_ShortMenu()
    Dim shortMenu As Object

    Set shortMenu = Application.CommandBars("MyComputer")
    With shortMenu
       .ShowPopup
    End With
End Sub


Sub Delete_ShortMenu()
    Application.CommandBars("MyComputer").Delete
End Sub


Sub Images()
    Dim i As Integer
    Dim j As Integer
    Dim total As Integer
    Dim buttonId As Integer
    Dim buttonName As String
    Dim myControl As CommandBarControl
    Dim bar As CommandBar
    
    On Error GoTo ErrorHandler
    
    Workbooks.Add
    Range("A1").Select
    With ActiveCell
        .Value = "Image"
        .Offset(0, 1) = "Index"
        .Offset(0, 2) = "Name"
        .Offset(0, 3) = "FaceID"
        .Offset(0, 4) = "CommandBar Name (Index)"
    End With
    
    For j = 1 To Application.CommandBars.Count
    
        Set bar = CommandBars(j)
        total = bar.Controls.Count
        
        With bar
            For i = 1 To total
                buttonName = .Controls(i).Caption
                buttonId = .Controls(i).ID
                
                Set myControl = CommandBars.FindControl(ID:=buttonId)
                
                myControl.CopyFace ' error could occur here
                  
                ActiveCell.Offset(1, 0).Select
                Sheets(1).Paste
                
                With ActiveCell
                    .Offset(0, 1).Value = buttonId
                    .Offset(0, 2).Value = buttonName
                    .Offset(0, 3).Value = myControl.FaceID
                    .Offset(0, 4).Value = bar.Name & " (" & j & ")"
                End With
StartNext:
            Next i
        End With
    Next j
    
    Columns("A:E").EntireColumn.AutoFit
    Exit Sub
ErrorHandler:
    Resume StartNext
End Sub


'----------------------------------------------------------------------------------------------------
' Hands-On 21-4
' This code is also available in the Ex07_HandsOn\Practice_Ribbon1.txt file
' This code is also available in the Practice_Ribbon_org.xml file
'----------------------------------------------------------------------------------------------------

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon startFromScratch="false">
    <tabs>
      <tab idMso="TabHome">
        <group idMso="GroupStyles" visible="false" />
      </tab>
      <tab id="TabJK1" label="Favorite">
        <group id="GroupJK1" label="SmallApps">
	  <button id="btnNotes" label="Notepad" image="Note1" size="large" onAction="OpenNotepad" 
	   screentip="Open Windows Notepad"
           supertip="It is recommended that you save your notes about this worksheet in a simple text file."/>
	  <button id="btnCharMap" label="CharMap" imageMso="SymbolInsert" 
           size="large" onAction="OpenCharmap" />
         </group>
        <group id="GroupJK2" label="Print/Email" >
          <button idMso="FilePrintQuick" size="normal" />
          <button idMso="FileSendAsAttachment" size="normal" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

'----------------------------------------------------------------------------------------------------

'Code in Step 8 (Hands-On 21-4)
'Code in the Practice_Ribbon1.xml.rels file (see the Completed_customUI/_rels 
'folder in the downloadable files)

<?xml version="1.0" encoding="utf-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/
relationships">
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/
relationships/image" Target="images/Note.gif" Id="Note1" />
</Relationships>


'----------------------------------------------------------------------------------------------------
' Hands-On 21-5 - Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------------

Public Sub OpenNotepad(ctl As IRibbonControl)
    Shell "Notepad.exe", vbNormalFocus
End Sub


Public Sub OpenCharmap(ctl As IRibbonControl)
    Shell "Charmap.exe", vbNormalFocus
End Sub


'----------------------------------------------------------------------------------------------------
' XML code in the "Using Images in Ribbon Customizations" section
' This code is also available in the Practice_Ribbon1_org2.xml file
'----------------------------------------------------------------------------------------------------

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" loadImage="OnLoadImage">
  <ribbon startFromScratch="false">
    <tabs>
      <tab idMso="TabHome">
        <group idMso="GroupStyles" visible="false" />
      </tab>
      <tab id="TabJK1" label="Favorite">
        <group id="GroupJK1" label="SmallApps">
	  <button id="btnNotes" label="Notepad" image="Note1" size="large" onAction="OpenNotepad" 
	   screentip="Open Windows Notepad"
           supertip="It is recommended that you save your notes about this worksheet in a simple text file."/>
	  <button id="btnCharMap" label="CharMap"
           imageMso="SymbolInsert" size="large" onAction="OpenCharmap" />
	  <button id="btnCalc" label="Calculator"
		image="DownArrow.gif" onAction="OpenCalculator" />
         </group>
        <group id="GroupJK2" label="Print/Email" >
          <button idMso="FilePrintQuick" size="normal" />
          <button idMso="FileSendAsAttachment" size="normal" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

'------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'------------------------------------------------------------------------------------------

Public Sub OnLoadImage(imgName As String, ByRef image)
    Dim strImgFileName As String
    strImgFileName = "C:\Ex07_HandsOn\Extra Images\" & imgName
    Set image = LoadPicture(strImgFileName)
End Sub


Public Sub OpenCalculator(ctl As IRibbonControl)
    Shell "Calc.exe", vbNormalFocus
End Sub


Sub OnGetPressed(control As IRibbonControl, _
            ByRef pressed)
    If control.id = "tglR1C1" Then
        pressed = False
    End If
End Sub


Sub SwitchRefStyle(control As IRibbonControl, _
            pressed As Boolean)
    If pressed Then
        Application.ReferenceStyle = xlR1C1
    Else
        Application.ReferenceStyle = xlA1
    End If
End Sub


'-------------------------------------------------------------------------------------------
' XML code in the "Creating Split Buttons, Menus, and Submenus" section
'-------------------------------------------------------------------------------------------

<splitButton id="btnSplit1" size="large" >
    <button id="btnGoTo" label="Navigate To..." imageMso="GoTo" />
        <menu id="mnuGoTo" label="Spreadsheet Navigation" itemSize="normal" >
           <menuSeparator id="mnuDiv1" title="Formulas and Constants" />
             <button id="btnFormulas" label="Select Formulas" onAction="GoToSpecial" />
	     <button id="btnNumbers" label="Select Numbers Only" onAction="GoToSpecial" />
             <button id="btnText" label="Select Text Only"  onAction="GoToSpecial" />
             <menuSeparator id="mnuDiv2" title="Special Cells" />
             <button id="btnBlanks" label="Select blank cells" onAction="GoToSpecial" />
             <button id="btnLast" label="Select last cell" onAction="GoToSpecial"/>
	   </menu>
</splitButton>

'-------------------------------------------------------------------------------------------

Sub GoToSpecial(control As IRibbonControl)
    On Error Resume Next
    Range("A1").Select

    If control.id = "btnFormulas" Then
        Selection.SpecialCells(xlCellTypeFormulas, 23).Select
    ElseIf control.id = "btnNumbers" Then
        Selection.SpecialCells(xlCellTypeConstants, 1).Select
    ElseIf control.id = "btnText" Then
        Selection.SpecialCells(xlCellTypeConstants, 2).Select
    ElseIf control.id = "btnBlanks" Then
        Selection.SpecialCells(xlCellTypeBlanks).Select
    ElseIf control.id = "btnLast" Then
        Selection.SpecialCells(xlCellTypeLastCell).Select
    End If
End Sub


'-------------------------------------------------------------------------------------------
' XML code in the "Creating Check Boxes" section
'-------------------------------------------------------------------------------------------

<separator id="OtherControlsDiv1" />
	   <labelControl id="TitleForBox1" label="Show or Hide Screen Elements" />
	   <box id="boxLayout1">
	      <checkBox id="chkGridlines" label="Gridlines" visible="true" getPressed="OnGetPressed"
                  onAction="DoSomething" />
              <checkBox id="chkFormulaBar" label="Formula Bar" visible="true" getPressed="OnGetPressed"
		  onAction="DoSomething" />
           </box>

'-------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'-------------------------------------------------------------------------------------------

Sub OnGetPressed(control As IRibbonControl, _
            ByRef pressed)
    If control.ID = "tglR1C1" Then
        pressed = False
    End If
    
    If control.id = "chkGridlines" And _
        ActiveWindow.DisplayGridlines = True Then
        pressed = True
    ElseIf control.id = "chkGridlines" And _
        ActiveWindow.DisplayGridlines = False Then
        pressed = False
    End If
    
    If control.id = "chkFormulaBar" And _
        Application.DisplayFormulaBar = True Then
        pressed = True
    ElseIf control.id = "chkFormulaBar" And _
    Application.DisplayFormulaBar = False Then
        pressed = False
    End If
End Sub


Sub DoSomething(ctl As IRibbonControl, _
                pressed As Boolean)

    If ctl.id = "chkGridlines" And pressed Then
       ActiveWindow.DisplayGridlines = True
    ElseIf ctl.id = "chkGridlines" And Not pressed Then
        ActiveWindow.DisplayGridlines = False
    ElseIf ctl.id = "chkFormulaBar" And pressed Then
        Application.DisplayFormulaBar = True
    ElseIf ctl.id = "chkFormulaBar" And Not pressed Then
        Application.DisplayFormulaBar = False
    End If
End Sub


'-------------------------------------------------------------------------------------------
' XML Code in the "Creating Edit Boxes" section
'-------------------------------------------------------------------------------------------

<editBox id="txtFullName" label="First and Last Name:"
              sizeString="AAAAAAAAAAAAAAAA" maxLength="25"
              onChange="onFullNameChange" />

'-------------------------------------------------------------------------------------------

'Code in the Practice_Ribbon.xlsm file
'-------------------------------------------------------------------------------------------

Public Sub onFullNameChange(ctl As IRibbonControl, _
                    text As String)
    If text <> "" Then
       MsgBox "You've entered '" & text & _
         "' in the edit box."
    End If
End Sub


'-------------------------------------------------------------------------------------------
' XML code in the "Creating Combo Boxes and Drop-Downs" section


<separator id="OtherControlsDiv2" />
            <comboBox id="cboDepartment" label="Departments" supertip="Select Department"
               onChange="OnChangeDept" >
              <item id="Marketing" label="Marketing" />
              <item id="Sales" label="Sales" />
              <item id="Personnel" label="Personnel" />
              <item id="ResearchAndDevelopment" label="Research and Development" />
            </comboBox>

'---------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'---------------------------------------------------------------------------------------------

Public Sub OnChangeDept(ctl As IRibbonControl, _
               text As String)
       MsgBox "You selected " & text & " department."
End Sub

'---------------------------------------------------------------------------------------------
<dropDown id="drpBoro" label="City Borough" 
                   supertip="Select City Borough"
                   onAction="OnActionBoro" >
              <item id="M" label="Manhattan" />
              <item id="B" label="Brooklyn" />
              <item id="Q" label="Queens" />
              <item id="I" label="Staten Island" />
              <item id="X" label="Bronx" />
            </dropDown>

'---------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'---------------------------------------------------------------------------------------------

Public Sub OnActionBoro(ctl As IRibbonControl, _
         ByRef selectedId As String, _
         ByRef selectedIndex As Integer)
    MsgBox "Index=" & selectedIndex & " ID=" & selectedId
End Sub


'---------------------------------------------------------------------------------------------
' XML code in the "Creating a Gallery Control" section
'---------------------------------------------------------------------------------------------
<gallery id="glHolidays" label="Holidays" columns="3" rows="4"
   getImage="OnGetImage" getItemCount="OnGetItemCount"
   getItemLabel="OnGetItemLabel" getItemImage="OnGetItemImage"
   getItemID="onGetItemID" onAction="onSelectedItem" />

'----------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------

Public Sub OnGetImage(ctl As IRibbonControl, ByRef image)
    Select Case ctl.id
      Case "glHolidays"
         Set image = LoadPicture("C:\Ex07_HandsOn\Extra Images\Square0.gif")
    End Select
End Sub


Public Sub OnGetItemCount(ctl As IRibbonControl, ByRef count)
  count = 12
End Sub


Public Sub OnGetItemLabel(ctl As IRibbonControl, _
                index As Integer, ByRef label)
    label = MonthName(index + 1)
End Sub


Public Sub OnGetItemImage(ctl As IRibbonControl, _
        index As Integer, ByRef image)
    Dim imgPath As String
    
    imgPath = "C:\Ex07_HandsOn\Extra Images\square"
    Set image = LoadPicture(imgPath & index + 1 & ".gif")
End Sub


Public Sub onGetItemID(ctl As IRibbonControl, _
                index As Integer, ByRef id)
    id = MonthName(index + 1)
End Sub


Public Sub onSelectedItem(ctl As IRibbonControl, _
                    selectedId As String, _
                    selectedIndex As Integer)
    Select Case selectedIndex
        Case 6
            MsgBox "Holiday 1: Independence Day, July 4th", _
            vbInformation + vbOKOnly, _
            selectedId & " Holidays"
            
        Case 11
            MsgBox "Holiday 1: Christmas Day, December 25th", _
            vbInformation + vbOKOnly, _
            selectedId & " Holidays"
        Case Else
            MsgBox "Please program holidays for " & selectedId & ".", _
            vbInformation + vbOKOnly, _
            " Under Construction"
    End Select   
End Sub

'----------------------------------------------------------------------------------------------------
' XML code in the "Creating a Dialog Box Launcher" section
'----------------------------------------------------------------------------------------------------

<dialogBoxLauncher>
    <button id="Launch1" screentip="Show Auto Correct Dialog"
    onAction="OnActionLaunch" />
</dialogBoxLauncher>

'----------------------------------------------------------------------------------------------------

Public Sub OnActionLaunch(ctl As IRibbonControl)
    Application.Dialogs(xlDialogAutoCorrect).Show
End Sub


'----------------------------------------------------------------------------------------------------
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
loadImage="OnLoadImage" >
  <ribbon startFromScratch="false">
    <tabs>
      <tab idMso="TabHome">
        <group idMso="GroupStyles" visible="false" />
      </tab>
      <tab id="TabJK1" label="Favorite">
        <group id="GroupJK1" label="SmallApps">
	  <button id="btnNotes" label="Notepad" image="Note1" size="large" onAction="OpenNotepad" 
	   screentip="Open Windows Notepad"
           supertip="It is recommended that you save your notes about this worksheet in a simple text file."/>
	  <button id="btnCharMap" label="CharMap"
           imageMso="SymbolInsert" size="large" onAction="OpenCharmap" />
	  <button id="btnCalc" label="Calculator"
		image="DownArrow.gif" onAction="OpenCalculator" />
         </group>
        <group id="GroupJK2" label="Print/Email" >
          <button idMso="FilePrintQuick" size="normal" />
          <button idMso="FileSendAsAttachment" size="normal" />
        </group>
	<group id="GroupJK3" label="Various Controls" >
	  <toggleButton id="tglR1C1" label="Reference Style" size="normal"
           getPressed="OnGetPressed" onAction="SwitchRefStyle" />
	  <splitButton id="btnSplit1" size="large" >
	    <button id="btnGoTo" label="Navigate To..." imageMso="GoTo" />
            <menu id="mnuGoTo" label="Spreadsheet Navigation" itemSize="normal" >
              <menuSeparator id="mnuDiv1" title="Formulas and Constants" />
               <button id="btnFormulas" label="Select Formulas" onAction="GoToSpecial" />
	       <button id="btnNumbers" label="Select Numbers Only" onAction="GoToSpecial" />
               <button id="btnText" label="Select Text Only"  onAction="GoToSpecial" />
               <menuSeparator id="mnuDiv2" title="Special Cells" />
               <button id="btnBlanks" label="Select blank cells" onAction="GoToSpecial" />
               <button id="btnLast" label="Select last cell" onAction="GoToSpecial"/>
	    </menu>
	  </splitButton>
	  <separator id="OtherControlsDiv1" />
	   <labelControl id="TitleForBox1" label="Show or Hide Screen Elements" />
	   <box id="boxLayout1">
	      <checkBox id="chkGridlines" label="Gridlines" visible="true" getPressed="OnGetPressed"
                  onAction="DoSomething" />
              <checkBox id="chkFormulaBar" label="Formula Bar" visible="true" getPressed="OnGetPressed"
		  onAction="DoSomething" />
           </box>
	   <editBox id="txtFullName" label="First and Last Name:"
              sizeString="AAAAAAAAAAAAAAAA" maxLength="25"
              onChange="onFullNameChange" />
	  <separator id="OtherControlsDiv2" />
            <comboBox id="cboDepartment" label="Departments" supertip="Select Department"
               onChange="OnChangeDept" >
              <item id="Marketing" label="Marketing" />
              <item id="Sales" label="Sales" />
              <item id="Personnel" label="Personnel" />
              <item id="ResearchAndDevelopment" label="Research and Development" />
            </comboBox>
            <dropDown id="drpBoro" label="City Borough" 
                   supertip="Select City Borough"
                   onAction="OnActionBoro" >
              <item id="M" label="Manhattan" />
              <item id="B" label="Brooklyn" />
              <item id="Q" label="Queens" />
              <item id="I" label="Staten Island" />
              <item id="X" label="Bronx" />
            </dropDown>
	    <gallery id="glHolidays" label="Holidays" columns="3" rows="4"
	      getImage="OnGetImage" getItemCount="OnGetItemCount"
              getItemLabel="OnGetItemLabel" getItemImage="OnGetItemImage"
              getItemID="onGetItemID" onAction="onSelectedItem" />
            <dialogBoxLauncher>
              <button id="Launch1" screentip="Show Auto Correct Dialog"  
               onAction="OnActionLaunch" />
            </dialogBoxLauncher>
	</group>
      </tab>
    </tabs>
  </ribbon>
</customUI>


'----------------------------------------------------------------------------------------------------
' XML code in the "Disabling a Control" section
'----------------------------------------------------------------------------------------------------

<!-- Built-in commands section -->
<commands>
<command idMso="NameManager" onAction="DisableNameManager" />
</commands>

'----------------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------------

Sub DisableNameManager(ctl As IRibbonControl, _
                       ByRef cancelDefault)
    MsgBox "You are not authorized to use this function."
    cancelDefault = True
End Sub

'----------------------------------------------------------------------------------------------------
' XML code in the "Repurposing a Built-in Control" section
'----------------------------------------------------------------------------------------------------

<command idMso="PictureInsertFromFile" onAction="CopyPicture" />

'----------------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------------

Public Sub CopyPicture(ctl As IRibbonControl, _
                ByRef cancelDefault)
    If ActiveSheet.Name = "Sheet1" Then
        ' display the CopyPicture dialog box instead
        Application.Dialogs(xlDialogCopyPicture).Show
    Else
        cancelDefault = False
    End If
End Sub


'----------------------------------------------------------------------------------------------------
' XML code in the "Repurposing a Built-in Control" section
'----------------------------------------------------------------------------------------------------
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
     loadImage="OnLoadImage" onLoad="RefreshMe">

'----------------------------------------------------------------------------------------------------
'Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------------

Public objRibbon As IRibbonUI
Private strUserTxt As String

'callback for the onLoad attribute of customUI
Public Sub RefreshMe(ribbon As IRibbonUI)
    Set objRibbon = ribbon
End Sub

'----------------------------------------------------------------------------------------------------
<editBox id="txtFullName" label="First and Last Name:"
  sizeString="AAAAAAAAAAAAAAAAAA" maxLength="25"
  getText="getEditBoxText" onChange="onFullNameChangeToUcase" />

'----------------------------------------------------------------------------------------------------

'Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------------

Public Sub getEditBoxText(control As IRibbonControl, _
            ByRef text)
    text = UCase(strUserTxt)
End Sub


Public Sub onFullNameChangeToUcase(ByVal control As IRibbonControl, _
                text As String)
    If text <> "" Then
        strUserTxt = text
        objRibbon.InvalidateControl "txtFullName"
    End If
End Sub


'----------------------------------------------------------------------------------------------------
' XML code in the "CommandBar Objects and the Ribbon" section
'----------------------------------------------------------------------------------------------------

<button id="btnWordWizard" label="Use Thesaurus" size="normal"
getImage="onGetBitmap" onAction="DoDefaultPlus" />

'----------------------------------------------------------------------------------------------------

'Code in the Practice_Ribbon.xlsm file
'----------------------------------------------------------------------------------------------------

Sub onGetBitmap(ctl As IRibbonControl, ByRef image)
   Set image = Application.CommandBars. _
     GetImageMso("ResearchPane", 16, 16)
End Sub


Sub DoDefaultPlus(ctl As IRibbonControl)
    If Not IsNumeric(ActiveCell.Value) Then
        Application.CommandBars.ExecuteMso "Thesaurus"
    Else
        MsgBox "To use Thesaurus, select a cell " & _
        "containing text.", _
        vbOKOnly + vbInformation, "Action Required"
    End If
End Sub


'----------------------------------------------------------------------------------------------------
' XML code in the "Customizing the Microsoft Office Button Menu" section
'----------------------------------------------------------------------------------------------------

<ribbon startFromScratch="false">
<!-- Office Button Menu section -->
<officeMenu>
    <control idMso="MenuPublish" visible="false" />
     <menu idMso="FileSaveAsMenu">
       <button idMso="FileSaveAsWebPage" />
     </menu>
     <button id="btnNotes1" label="Open Notepad"
       image="Note1" insertBeforeMso="FileSave"
       onAction="OpenNotepad" />
</officeMenu>
<!--Other Ribbon Customization section -->
</ribbon>

'----------------------------------------------------------------------------------------------------

'----------------------------------------------------------------------------------------------------
' XML code in the "Customizing the Quick Access Toolbar (QAT)" section
'----------------------------------------------------------------------------------------------------
<ribbon startFromScratch="true">
  <qat>
    <sharedControls>
      <button idMso="FilePrintQuick" />
    </sharedControls>
    <documentControls>
      <button id="btnCalc2" label="Calculator"
      image="DownArrow.gif" onAction="OpenCalculator" />
    </documentControls>
</qat>

'----------------------------------------------------------------------------------------------------

















